/*
 * cfunc.c
 *
 *  Created on: Dec 14, 2023
 *      Author: boen
 */

#include <platform.h>


/**
  * @brief
  * @param
  * @retval
  */
float inline deg2rad(float x)
{
	return (x*3.1415926f/180.0f);
}


/**
  * @brief
  * @param
  * @retval
  */
float inline rad2deg(float x)
{
	return (x*180.0f/3.1415926f);
}


/**
  * @brief
  * @param
  * @retval
  */
void float2byte(float floatNum, unsigned char *byteArry)
{
	unsigned char *pchar = (unsigned char *)&floatNum;
	char i;

	for (i = 0; i < sizeof(float); i++)
	{
		*byteArry = *pchar;
		pchar++;
		byteArry++;
	}
}


/**
  * @brief
  * @param
  * @retval
  */
float byte2float(unsigned char* byteArray)
{
  return *((float*)byteArray);
}


/**
  * @brief
  * @param
  * @retval
  */
float target_limit(float insert,float low,float high)
{
    if (insert < low)
        return low;
    else if (insert > high)
        return high;
    else
        return insert;
}


/**
  * @brief 延时函数，延时us,(非准确定时)
  * @param
  * @retval
  */
void delay_us(uint16_t tim)
{
	//uint32_t tmp = tim*4800;
	uint32_t tmp = tim*480;
	while(tmp)
	{
		tmp--;
	}
}
